package com.hyfrogx.modules.zoom.controller;

import com.alibaba.fastjson.JSONArray;
import com.hyfrogx.common.exception.MyException;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.sys.controller.AbstractController;
import com.hyfrogx.modules.zoom.entity.HyVipMeetConfig;
import com.hyfrogx.modules.zoom.param.ZoomPirce;
import com.hyfrogx.modules.zoom.service.HyVipMeetConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：Li9527
 * @date ：Created in 2019-11-15 13:15
 * @description：专属会议参会定价
 * @modified By：
 * @version: 1.0.0
 */
@RestController
@RequestMapping("/vipMeetConfig")
@Api(value = "专属参会价格管理controller", tags = {"后台--专属参会价格管理"})
public class HyVipMeetConfigController extends AbstractController {


    @Autowired
    HyVipMeetConfigService hyVipMeetConfigService;

    /**
     * 获取所有规模及定价
     *
     * @param
     * @throws MyException
     */
    @GetMapping("/getList")
    @ApiOperation("获取所有规模及定价")
    public R getMeetPrice() {
        try {
            List<HyVipMeetConfig> list = hyVipMeetConfigService.list();
            if (list != null) {
                return R.ok().put("data", list);
            } else {
                return R.error("查询失败");
            }
        } catch (MyException e) {
            return R.error(e.getMessage());
        }
    }

    /**
     * 根据规模修改价格<批量修改>
     *
     * @param jsonStr
     * @throws MyException
     */
    @PostMapping("/updateList")
    @ApiOperation("根据规模修改价格<批量修改>")
    public R updateList(String jsonStr) {
        try {
            JSONArray jsonArray = JSONArray.parseArray(jsonStr);
            List<HyVipMeetConfig> vipMeetConfigList = new ArrayList<>();
            for (int i = 0; i < jsonArray.size(); i++) {
                // json转对象,提供的参数有:channelId;channelName;isall;time;size;vodStatus
                HyVipMeetConfig hyVipMeetConfig = jsonArray.getObject(i, HyVipMeetConfig.class);
                vipMeetConfigList.add(hyVipMeetConfig);
            }
            Boolean flag = hyVipMeetConfigService.saveOrUpdateBatch(vipMeetConfigList);
            if(flag){
                return R.ok("修改成功");
            }else{
                return R.error("修改失败");
            }
        } catch (MyException e) {
            return R.error(e.getMessage());
        }
    }


}
